package com.dounine.clouddisk360.parser.deserializer.user.size;

import java.io.IOException;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.protocol.HttpContext;

import com.dounine.clouddisk360.exception.CloudDiskException;
import com.dounine.clouddisk360.parser.deserializer.BaseConst;
import com.dounine.clouddisk360.parser.deserializer.BaseRequestInterceptor;
import com.dounine.clouddisk360.parser.deserializer.MsgConst;
import com.dounine.clouddisk360.parser.deserializer.authtoken.AuthTokenConst;

public class UserSizeRequestInterceptor extends BaseRequestInterceptor implements HttpRequestInterceptor{

	@Override
	public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
		super.process(request, context);
		request.addHeader(UserSizeConst.HOST_KEY, UserSizeConst.HOST_VAL);
		request.addHeader(UserSizeConst.REFERER_KEY, UserSizeConst.REFERER_VAL);
		if(null==context.getAttribute(BaseConst.REQUEST_HOST_NAME)){
			throw new CloudDiskException(MsgConst.HOST_VALUE_NOT_NULL);
		}else{
			request.addHeader(AuthTokenConst.HOST_KEY, String.valueOf(context.getAttribute(BaseConst.REQUEST_HOST_NAME)));
		}
	}

}
